package com.clevertech.tests.Utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

/**
 * Created by IntelliJ IDEA.
 * User: pavel
 * Date: Jun 17, 2010
 * Time: 9:00:19 PM
 * To change this template use File | Settings | File Templates.
 */
public class ClevertechProperties extends Properties{

    /**
     * Created by IntelliJ IDEA.
     * User: User
     * Date: Jul 21, 2009
     * Time: 2:41:49 PM
     * To change this template use File | Settings | File Templates.
     */

        public static final String REPORT_PATH = "REPORT_PATH";


        public static final String ENV_ID = "ENV_ID";

        public static final String  BROWSER="BROWSER";

        public static final String RESOURCE_PATH = "RESOURCE_PATH";

        public static final String CONFIG_PATH = "CONFIG_PATH";

        public static final String MAKE_SCREENSHOT="MAKE_SCREENSHOT";

        public static final String CAPTURE_NETWORK_TRAFFIC="CAPTURE_NETWORK_TRAFFIC";

        private static String reportPath;

        private static String envId;

        private static String browser;

        private static String resourcePath;

        private static String configPath;

        private static ClevertechProperties instance = null;

        private static boolean makeScreenshot= false;

        private static boolean captureNetworkTraffic= false;

        private ClevertechProperties() {

            Class mc = ClevertechProperties.class;

            URL url = mc.getResource("be2.properties");

            try {
                loadProperties(url.getPath());
            } catch (Exception e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }


    public static ClevertechProperties getInstance() {
            if(instance == null)
                instance = new ClevertechProperties();

            return instance;
        }

        /**
         * Loads provider properties from the property file.
         *
         * @throws java.io.FileNotFoundException
         *             if property file doesn't exist.
         * @throws java.io.IOException
         *             if there was a file reading problem.
         */
        private void loadProperties(String propFileName) throws Exception {

            try {
                File propFile = new File(propFileName);
                InputStream in = new FileInputStream(propFile);
                this.load(in);

                reportPath = this.getProperty(REPORT_PATH);
                envId = this.getProperty(ENV_ID);
                browser = this.getProperty(BROWSER);
                resourcePath = this.getProperty(RESOURCE_PATH);
                configPath = this.getProperty(CONFIG_PATH);
                makeScreenshot= Boolean.valueOf(this.getProperty(MAKE_SCREENSHOT));
                captureNetworkTraffic= Boolean.valueOf(this.getProperty(CAPTURE_NETWORK_TRAFFIC));
            }
            catch (Exception ex) {
                ex.printStackTrace();
            }

        }
        /**
           * Returns path where all resources which are needed<br/>
           * for automation tests are located<br>
           * This path can be edited in file <tt>be2.properties</tt> <br>
           * by the name {@link Be2Properties#RESOURCE_PATH}
           * @return
           */
          public String getResourcePath() {
              return resourcePath;
          }

        /**
           * Returns path where all configurations which are needed<br/>
           * for automation tests are located<br>
           * This path can be edited in file <tt>be2.properties</tt> <br>
           * by the name {@link Be2Properties#CONFIG_PATH}
           * @return
           */
          public String getConfigPath() {
              return configPath;
          }

        public static boolean getCaptureNetworkTraffic() {
            return captureNetworkTraffic;
        }

        public static void setCaptureNetworkTraffic(boolean networkTraffic) {
            captureNetworkTraffic = networkTraffic;
        }

        public static boolean getMakeScreenshot() {
            return makeScreenshot;
        }

        public static void setMakeScreenshot(boolean screenshot) {
            makeScreenshot = screenshot;
        }

        public static String getBrowser() {
            return browser;
        }

        public static void setBrowser(String browser) {
            ClevertechProperties.browser = browser;
        }

        public static String getEnvId() {
            return envId;
        }

        public static void setEnvId(String envId) {
            ClevertechProperties.envId = envId;
        }

        public static String getReportPath() {
            return reportPath;
        }

        public static void setReportPath(String reportPath) {
            ClevertechProperties.reportPath = reportPath;
        }
    }


